package com.liuli.action;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.liuli.entity.ResumeEdu;
import com.liuli.service.ResumeEduService;
import com.liuli.utils.ReturnJson;
import com.opensymphony.xwork2.ModelDriven;

public class ResumeEduAction extends BaseAction implements ModelDriven<ResumeEdu> {
	
	@Autowired
	@Qualifier("eduService")
	private ResumeEduService eduService;
	
	private ResumeEdu edu;
	
	
	
	/**
	 * 添加教育经历
	 */
	public void  addEdu(){
		JSONObject json = new JSONObject();
		try {
			eduService.save(edu);
			json.put("errcode", 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}

	
	/**
	 * 修改教育经历
	 */
	public void  editEdu(){
		JSONObject json = new JSONObject();
		try {
			eduService.update(edu);
			json.put("errcode", 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}

	/**
	 * 删除教育经历
	 */
	public void  delEdu(){
		JSONObject json = new JSONObject();
		try {
			eduService.delete(edu.getEdid());
			json.put("errcode", 0);
		} catch (Exception e) {
			json.put("errcode", 40014);  //删除失败
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}
	
	
	
	public ResumeEdu getEdu() {
		return edu;
	}


	public void setEdu(ResumeEdu edu) {
		this.edu = edu;
	}

	public ResumeEduService getEduService() {
		return eduService;
	}

	public void setEduService(ResumeEduService eduService) {
		this.eduService = eduService;
	}

	


	@Override
	public ResumeEdu getModel() {
		if(edu==null){
			edu = new ResumeEdu();
		}
		return edu;
	}

}
